class fliter():
    def __init__(self, fileName):
        dirty_dict = self.get_dirty(file)
        self.fliteredString = self.fliterMaster(dirty_dict)

    def get_dirty(self, fileName=''):
        with open (fileName, 'r', encoding='utf-8') as f:
            re = f.readlines()

        for i in range(len(re)):
            re[i] = re[i].strip('\n')

        return(re)

    def fliterMaster(self, dirty_dict):
        instr = input("请输入：")
        self.originString = instr
        for i in dirty_dict:
            inArray = self.str2array(instr)
            inDirtArray = self.str2array(i)

            pos_list = self.get_pos(inArray, inDirtArray[0])
            if pos_list is None:
                continue
            else:
                for tag in pos_list:
                    inArray = self.fliterWorker(tag, inArray, inDirtArray)
                instr = ''.join(inArray)

        return instr

    def str2array(self, instr):

        redict = []
        for i in instr:
            redict.append(i)
        return redict

    def get_pos(self, instr, word):

        try:
            re = instr.index(word)
            resp = []
            resp.append(re)
            while(1):
                try:
                    re = instr.index(word, re+1, len(instr))
                    resp.append(re)
                except Exception as e:
                    break
            return resp

        except Exception as e:
            return None


    def fliterWorker(self, tag, inArray, inDirtArray):
        resp = ""
        resp_temp = ""
        for i in range(tag):
            resp += inArray[i]

        for i in range(len(inDirtArray)):
            if inArray[tag+i] == inDirtArray[i]:
                resp_temp += "*"
            else:
                resp_temp = ''
                break

        if resp_temp == '':
            return inArray

        else:
            resp += resp_temp
            for i in range(tag+len(inDirtArray), len(inArray)):

                resp += inArray[i]
        return resp


if __name__ == '__main__':
    file = '01.txt'
    fliter1 = fliter(file)
    print("未过滤字符串为：" + fliter1.originString)
    print("过滤后字符串为：" + fliter1.fliteredString)